var class_num=location.search;
class_num=class_num.split('?')[1];
$('.class_num').append(class_num);
$('#add-sharedfile').click(function () {
    window.location.href,location='add_sharedfile.html?'+class_num;
});

if (islogin()) {
    $.post({
        url:'../../requests/teacher/select_sharedfile.php',
        data:{'class':class_num},
        success:function (data) {
            for (var i = 0; i < data.length; i++) {
                var dom=" <div class='list-block'><ul>\n" +
                    "                   <li class=\"item-content\">\n" +
                    "                       <div class=\"item-inner\">\n" +
                    "                           <div class=\"item-title\">文件名</div>\n" +
                    "                           <div class=\"item-after\">"+data[i].name+"</div>\n" +
                    "                       </div>\n" +
                    "                   </li>\n" +
                    "                   <li class=\"item-content\">\n" +
                    "                    <div class=\"item-inner\"><div class='item-title'>\n" +
                    "                        <span><button class=\"button btn_del del_"+data[i].Id+"\">删除</button></span>\n" +
                    "                        <span><button class=\"button btn_move move_"+data[i].Id+"\">移至私有</button></span></div>\n" +
                    "                        <div class='item-after'><span><a href='../../"+data[i].path+"'>下载<span class=\"icon icon-download\"></span></a></span></div>\n" +
                    "                    </div>\n" +
                    "                   </li>\n" +
                    "               </ul></div>";
                $('.sharedfile_box').append(dom);
            }
        }
    });

    $('.sharedfile_box').on('click','.btn_del',function () {
        var str=$(this).attr('class');
        var id=str.split(" ")[2].split('_')[1];
        $$.confirm('确认删除？',function () {
            $.post({
                url:'../../requests/teacher/del_sharedfile.php',
                data:{'id':id},
                success:function (data) {
                    if (data == "1") {
                        $$.alert('删除成功！',function () {
                            location.reload(true);
                        });
                    }
                }
            });
        });
    });

    $('.sharedfile_box').on('click','.btn_move',function () {
        var id=$(this).attr('class').split(' ')[2].split('_')[1];
        console.log(id);
        $$.confirm("确认移动？",function () {
            $.post({
                url:'../../requests/teacher/move_shared.php',
                data:{'id':id},
                success:function (data) {
                    if (data == '1') {
                        location.reload(true);
                    }
                    else if (data == 'file_exist') {
                        $$.alert('文件名已存在！');
                    }
                }
            });
        });
    });
}
else window.location.href='../../index.html';